package design;

public class SingleLanHan
{
    //私有化
    private SingleLanHan(){}
    private static SingleLanHan singleLanHan;

    private static SingleLanHan getInstance()
    {
        if (singleLanHan == null)
        {
            try
            {
                Thread.sleep(1000);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
            synchronized (SingleLanHan.class)
            {
                if (singleLanHan == null)
                {
                    singleLanHan = new SingleLanHan();
                }
            }

        }
        return singleLanHan;
    }

    public static void main(String[] args)
    {
        for (int i = 0; i < 200; i++)
        {
            new Thread(() -> System.out.println(SingleLanHan.getInstance().hashCode())).start();
        }
    }
}
